#ifndef __TRAPDOOR_BLOCK_H__
#define __TRAPDOOR_BLOCK_H__

#include "Block.hpp"

namespace PocketSurvival
{    
    // 活板门基类, 未完成...  未添加电路支持
    class TrapdoorBlock : public Block
    {
    public:
		TrapdoorBlock();
        virtual BlockPlacementData getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult) override;
        virtual const std::vector<BoundingBox> &getCustomCollisionBoxes(int32_t value) override;
		
		static inline int32_t GetRotation(int32_t data);
		static inline bool GetOpen(int32_t data);
		static inline bool GetUpsideDown(int32_t data);
		static inline int32_t SetRotation(int32_t data, int32_t rotation);
		static inline int32_t SetOpen(int32_t data, bool open);
		static inline int32_t SetUpsideDown(int32_t data, bool upsideDown);
		static inline int32_t GetMountingFace(int32_t data);
    };

	inline int32_t TrapdoorBlock::GetRotation(int32_t data)
	{
		return data & 3;
	}
	inline bool TrapdoorBlock::GetOpen(int32_t data)
	{
		return (data & 4) != 0;
	}
	inline bool TrapdoorBlock::GetUpsideDown(int32_t data)
	{
		return (data & 8) != 0;
	}
	inline int32_t TrapdoorBlock::SetRotation(int32_t data, int32_t rotation)
	{
		return (data & -4) | (rotation & 3);
	}
	inline int32_t TrapdoorBlock::SetOpen(int32_t data, bool open)
	{
		if (open == false)
		{
			return data & -5;
		}
		return data | 4;
	}
	inline int32_t TrapdoorBlock::SetUpsideDown(int32_t data, bool upsideDown)
	{
		if (upsideDown == false)
		{
			return data & -9;
		}
		return data | 8;
	}
	inline int32_t TrapdoorBlock::GetMountingFace(int32_t data)
	{
		if (GetUpsideDown(data) == false)
		{
			return 4;
		}
		return 5;
	}

} // namespace PocketSurvival


#endif
